package org.example.创建型模式.抽象工厂模式.重构代码.Redis双集群升级_抽象工厂.factory;

import org.example.创建型模式.抽象工厂模式.重构代码.Redis双集群升级_抽象工厂.util.ClassLoaderUtils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author : hmxchen
 * @program : modules-api
 * @description :
 * @create : 2022-04-14 09:49
 **/
public class JDKInvocationHandler implements InvocationHandler {
    private ICacheAdapter cacheAdapter;

    public JDKInvocationHandler(ICacheAdapter cacheAdapter) {
        this.cacheAdapter = cacheAdapter;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return ICacheAdapter.class.getMethod(method.getName(), ClassLoaderUtils.getClazzByArgs(args)).invoke(cacheAdapter,args);
    }
}
